package com.tong.embeddedvr.controller;

import com.tong.embeddedvr.dto.HostDTO;
import com.tong.embeddedvr.service.impl.HostServiceImpl;
import com.tong.embeddedvr.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@CrossOrigin
@RestController
@RequestMapping("/host")
public class HostController {

    @Autowired
    UserServiceImpl userService;

    @Autowired
    HostServiceImpl hostServiceImpl;

    @RequestMapping("/add")
    public String addHost(HttpSession session, HostDTO hostDTO){
        return hostServiceImpl.addHost(hostDTO);
    }

    @RequestMapping("/updateInformation")
    public String updateInformation(HttpSession session,HostDTO hostDTO){
        return hostServiceImpl.updateInformation(hostDTO);
    }

    public String delete(HttpSession session,HostDTO hostDTO){
        HashMap<String, Object> map = new HashMap<>();
        hostDTO.setHostIsDelete(1);
        return hostServiceImpl.updateInformation(hostDTO);
    }

    /**
     * update information(include delete)
     * @return
     */
    @RequestMapping("/getall")
    public String getAll(HttpSession session){
        return hostServiceImpl.getAllHost();
    }
}
